# Adogs
# 时间: 2021/7/17 16:19
import random

import pygame
from actor import WalkDir, ShootDir
from actor.shoot_soldier import ShootSoldier


class RedArmyShootSoldier(ShootSoldier):
    """
    红军射击战士类
    方法：
    1.__init__(x, y)
    2.run(down_flag, key_list)
    """
    def __init__(self, x, y):
        """
        初始化函数
        :param x: 人物x坐标
        :param y: 人物y坐标
        """
        super(RedArmyShootSoldier, self).__init__("./resources/picture/chinese/red_army/red_army1.png",
                                                  "./resources/picture/chinese/red_army/red_army1-1.png",
                                                  x, y, "红军", 100)
        self.count = 15     # 计数器
        self.key = pygame.K_s   # 初始化方向向下

    def run(self, down_flag, key_list):
        """
        人物运动函数
        :param down_flag: bool型，判断是否点击按键
        :param key_list: 列表型，存储键盘上每个键的bool值，判断键是否按下
        :return: 无返回值
        """
        if self.count == -5:
            key = random.randint(0, 3)
            self.count = 15
            if key == 0:
                self.walk_action.set_dir(WalkDir.down)
                self.pos_y += 10
            elif key == 1:
                self.walk_action.set_dir(WalkDir.left)
                self.pos_x -= 10
            elif key == 2:
                self.walk_action.set_dir(WalkDir.right)
                self.pos_x += 10
            elif key == 3:
                self.walk_action.set_dir(WalkDir.on)
                self.pos_y -= 10
        elif self.count >= 0:
            self.count -= 1
        self.shoot_action.set_dir(ShootDir.not_shoot)

        if self.walk_action.walk_dir == WalkDir.down:
            self.pos_y += 10
        elif self.walk_action.walk_dir == WalkDir.on:
            self.pos_y += -10
        elif self.walk_action.walk_dir == WalkDir.left:
            self.pos_x += -10
        elif self.walk_action.walk_dir == WalkDir.right:
            self.pos_x += 10
